/*
 * demo1.cpp
 *
 *  Created on: 2012-8-20
 *      Author: huangyansheng
 */

#include <iostream>
#include <gtest/gtest.h>
//增加gmock的依赖
#include <gmock/gmock.h>

//引用依赖的头文件
#include "Shop_10.h"
#include "Product_10.h"

using namespace ::testing;
using namespace std;

//生成Mock类
class MOCK_Product : public BaseProduct_10 {
public:
	MOCK_METHOD1(getPrice,int(int id));
};

//修改我们的测试用例
TEST(total_10,price1) {
	BaseProduct_10 *bp=new Product_10();
	Shop_10 dd(bp);
	EXPECT_EQ(100, dd.total_10(1,10));
	EXPECT_EQ(100, dd.total_10(2,5));
	EXPECT_EQ(100, dd.total_10(5,2));
	EXPECT_EQ(100, dd.total_10(10,1));
}
TEST(total_10,price_zero) {
	BaseProduct_10 *bp=new Product_10();
		Shop_10 dd(bp);
	EXPECT_EQ(0, dd.total_10(1001,10));
	EXPECT_EQ(0, dd.total_10(10,0));
}
TEST(total_10,price_negative) {
	BaseProduct_10 *bp=new Product_10();
		Shop_10 dd(bp);
	EXPECT_EQ(-1, dd.total_10(100001,10));
	EXPECT_EQ(-1, dd.total_10(10,-1));
	EXPECT_EQ(-1, dd.total_10(-10,-1));
}

class ShopTest_10: public ::testing::Test {
public:
	Shop_10 *dd;
	BaseProduct_10 *bp;
	MOCK_Product *m;
	static void SetUpTestCase() {
		cout << "SetUpTestCase" << endl;
	}
	void SetUp() {
		bp=new Product_10;
		m=new MOCK_Product;
		dd = new Shop_10(bp);
	}
	void TearDown() {
		delete dd;
		delete bp;
		delete m;
	}
	static void TearDownTestCase() {
		cout << "TearDownTestCase" << endl;
	}
};
TEST_F(ShopTest_10,price1) {
	EXPECT_EQ(100, dd->total_10(1,10));
	EXPECT_EQ(100, dd->total_10(2,5));
	EXPECT_EQ(100, dd->total_10(5,2));
	EXPECT_EQ(100, dd->total_10(10,1));
}
TEST_F(ShopTest_10,price_zero) {
	EXPECT_EQ(0, dd->total_10(1001,10));
	EXPECT_EQ(0, dd->total_10(10,0));
}


//增加新的测试用例，假设price返回的内容会发生变更
TEST_F(ShopTest_10,price_zero_below) {
	dd=new Shop_10((BaseProduct_10*)m);
	EXPECT_CALL(*m,getPrice(11)).WillRepeatedly(Return(2));
	EXPECT_EQ(20, dd->total_10(11,10));
	EXPECT_EQ(0, dd->total_10(11,0));
}
TEST_F(ShopTest_10,price_normal) {
	dd=new Shop_10((BaseProduct_10*)m);
	//使用通配matcher
	EXPECT_CALL(*m,getPrice(_)).WillOnce(Return(2));
	EXPECT_EQ(4, dd->total_10(20,2));
	EXPECT_EQ(6, dd->total_10(30,3));
}
